package com.blacktea.creationalpatterns.simplefactorymodel.factory;

import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Component;
import com.blacktea.creationalpatterns.simplefactorymodel.service.Animal;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Optional;

/**
 * @description:
 * @author: black tea
 * @date: 2023/3/18 23:33
 */
@Component
public class AnimalFactory {

    @Resource
    Map<String, Animal> animalMap;

    public Optional<Animal> getAnimal(String animalType){
        if (animalType == null){
            return Optional.empty();
        }
        // 将首字母变小写
        String newAnimalType =  StrUtil.lowerFirst(animalType);
        return Optional.ofNullable(animalMap.get(newAnimalType));
    }

}
